﻿using SYJ.Factory;
using SYJ.IBLL;
using SYJ.IDAL;
using SYJ.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SYJ.BLL
{
    public abstract partial class BaseBLL<T> : IBaseBLL<T> where T : class, new()
    {
        
        protected IBaseDal<T> dal;
        //abstract~子类继承后必须实现
        protected abstract IBaseDal<T> GetDal();
        public BaseBLL() {
            dal = GetDal();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Insert(T t)
        {
            return dal.Insert(t);
        }
        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Insert(List<T> list)
        {
            return dal.Insert(list);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Update(T t)
        {
            return dal.Update(t);
        }
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool Update(List<T> list)
        {
            return dal.Update(list); 
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Delete(T t)
        {
            return dal.Delete(t);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool Delete(List<T> list)
        {
            return dal.Delete(list);
        }

        /// <summary>
        /// ID获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public T GetModel(int id)
        {
            return dal.GetModel(id);
        }
        /// <summary>
        /// 获取全部记录
        /// </summary>
        /// <returns></returns>
        public List<T> GetAll()
        {
            return dal.GetAll();
        }
        /// <summary>
        /// 分页获取
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<T> GetPage(QueryModel query,out long count)
        {
            return dal.GetPage(query,out count);
        }

        public List<T> Get(string sql)
        {
            return dal.Get(sql);
        }
        public List<T> Get(string sql, object param)
        {
            return dal.Get(sql, param);
        }
        public T GetModel(string sql)
        {
            return dal.GetModel(sql);
        }
        public T GetModel(string sql, object param)
        {
            return dal.GetModel(sql, param);
        }
    
    }
}
